package adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cyan.tools.base.BaseViewHolder;
import com.cyan.tools.base.RecyclerArrayAdapter;

import bean.NewsItem;
import menhoo.com.i8officelibrary.R;

/**
 * Created by pc on 2018/7/7.
 */

public class NewsListAdapter extends RecyclerArrayAdapter<NewsItem> {
    public NewsListAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(parent);
    }

    class ViewHolder extends BaseViewHolder<NewsItem> {
        TextView title;
        TextView date;

        public ViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_news);
            title = itemView.findViewById(R.id.title);
            date = itemView.findViewById(R.id.date);

        }

        @Override
        public void setData(NewsItem data) {
            title.setText(data.Title);
            date.setText(data.PubInWebDate);
            try {
                title.setTextColor(TextUtils.isEmpty(data.TitleColor) ? ContextCompat.getColor(getContext(), R.color.black) : Color.parseColor(data.TitleColor));
            } catch (Exception e) {
                title.setTextColor(ContextCompat.getColor(getContext(), R.color.black));
            }


        }
    }
}
